﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WineStore.DAL;
using PagedList.Mvc;
using PagedList;
using WineStore.Models;
using System.Data;
using System.IO;
using System.Data.Entity;

namespace WineStore.Controllers
{

    public class AboutUsController : Controller
    {

        // GET: /AboutUs/ShowAboutUs/

        public ActionResult ShowAboutUs()
        {
            using (var db = new WineDbContext())
            {
                var aboutus = db.AboutUs
                    .OrderByDescending(a => a.AboutUsId).ToList();

                return View(aboutus);
            }
        }


        // GET: /AboutUs/EditAboutUs/
        [HttpGet]
        public ActionResult EditAboutUs(int id = 0)
        {
            AboutUs aboutus = null;
            using (var db = new WineDbContext())
            {
                aboutus = db.AboutUs.Find(id);
                if (aboutus == null)
                {
                    return HttpNotFound();
                }
            }
            return View(aboutus);
        }

        // POST: /AboutUs/EditAboutUs/
        [HttpPost]
        [ValidateInput(false)]
        public ActionResult EditAboutUs(AboutUs aboutus)
        {
            try
            {
                using (var db = new WineDbContext())
                {
                    db.Entry(aboutus).State = EntityState.Modified;
                    db.SaveChanges();
                    return RedirectToAction("ShowAboutUs", "AboutUs");
                }

            }
            catch (DataException)
            {
                ModelState.AddModelError("", "Unable to save changes");
            }
            return View(aboutus);
        }

        // GET: /AboutUs/DeleteAboutUs/
        public ActionResult DeleteAboutUs(int id)
        {
            AboutUs aboutus = null;
            using (var db = new WineDbContext())
            {
                aboutus = db.AboutUs.Find(id);
                if (aboutus == null)
                {
                    return HttpNotFound();
                }
            }
            return View(aboutus);
        }

        // POST: /AboutUs/DeleteAboutUs/
        [HttpPost, ActionName("DeleteAboutUs")]
        public ActionResult DeleteConfirmed(int id)
        {
            AboutUs aboutus = null;
            try
            {
                using (var db = new WineDbContext())
                {
                    aboutus = db.AboutUs.Find(id);
                    db.Entry(aboutus).State = EntityState.Deleted;
                    db.SaveChanges();
                    return RedirectToAction("ShowAboutUs", "AboutUs");
                }
            }
            catch (DataException)
            {
                ModelState.AddModelError("", "Unable to save changes");
            }
            return View(aboutus);
        }
    }
}
